home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Personal Computer World 2009 February
/
PCWFEB09.iso
/
Software
/
Resources
/
Burning & Media
/
GB-PVR 1.2.13
/
GBPVR10213.msi
/
Cabs.w1.cab
/
Guide.aspx.cs367
< prev
next >
Wrap
Text File
|
2008-02-23
|
20KB
|
564 lines
using System;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using GBPVR.Public;
using GBPVRSchedule;
using gbweb.classes;
namespace gbweb
{
/// <summary>
/// Summary description for guide.
/// </summary>
public partial class guide : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlImage IMG4;
protected System.Web.UI.HtmlControls.HtmlImage IMG5;
private DateTime startTime;
private Settings guideParams;
//Guide display values that are stored in the users cookie
private static int minuteSpan;
private static int minuteInterval;
private static int minuteSlice;
private static int TimelineRepeat;
private static string useChannelIcons;
private static string channelIconHeight;
private static string channelIconWidth;
protected void Page_Load(object sender, System.EventArgs e)
{
guideParams = Global.Settings;
Session["GuideStartTime"] = null;
GetCookieValues();
if (!IsPostBack)
{
// populate date/time navigation controls
DateTime today = DateTime.Today;
for (int hours=0; hours < 24; hours++)
{
DateTime theHour = today.AddHours(hours);
for (int minutes=0; minutes < 60; minutes=minutes + minuteInterval)
{
DateTime theMinute = theHour.AddMinutes(minutes);
ListItem myLI = new ListItem(theMinute.ToShortTimeString(), theMinute.ToString("HH:mm"));
timeJump.Items.Add(myLI);
}
}
Global.FillGenreList(genreList);
}
if (ViewState["GuideStartTime"] == null)
{
if (guideParams.guideStartTime != "")
{
// default the start time to the configured default start time
startTime = Convert.ToDateTime(DateTime.Now.ToShortDateString() + " " + guideParams.guideStartTime);
}
else
{
// default to current time if the user has just logged in, or come from the 'manage recordings' page
startTime = DateTime.Now;
}
// remove seconds and miliseconds
startTime = startTime.AddSeconds(-startTime.Second);
startTime = startTime.AddMilliseconds(-startTime.Millisecond);
}
else
{
startTime = (DateTime)ViewState["GuideStartTime"];
}
if (Request.Form["__EVENTTARGET"] != null)
{
if (Request.Form["__EVENTTARGET"].IndexOf("viewleftbutton") != -1) ViewLeftButton_Click(null, null);
if (Request.Form["__EVENTTARGET"].IndexOf("viewrightbutton") != -1) ViewRightButton_Click(null, null);
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void GoButton_Click(object sender, System.EventArgs e)
{
startTime = DateTime.Parse(dateJump.SelectedValue + " " + timeJump.SelectedValue);
}
private void ViewLeftButton_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
startTime = startTime.AddMinutes(-minuteSpan);
}
private void ViewRightButton_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
startTime = startTime.AddMinutes(minuteSpan);
}
protected void Page_PreRender(object sender, System.EventArgs e)
{
Schedule scheduleHelper = Global.Schedule;
ProgrammeDisplay displayProgramme = new ProgrammeDisplay();
// build up a list of the recording we already know about
IDictionary knownRecordings = scheduleHelper.LoadKnownRecordings();
// normalize time period
startTime = startTime.AddMinutes(-startTime.Minute % minuteInterval);
DateTime endTime = startTime.AddMinutes(minuteSpan);
viewingDate.Text = startTime.ToLongDateString();
// store start time away for later use
ViewState["GuideStartTime"] = startTime;
// select the correct minutes setting
//timeJump.SelectedIndex = (int)(startTime.TimeOfDay.TotalMinutes / 30);
timeJump.SelectedValue = startTime.ToString("HH:mm");
// select correct date
//dateJump.SelectedIndex = (int)(startTime.Date.DayOfYear - DateTime.Now.AddDays(-1).Date.DayOfYear);
/*if (dateJump.Items.FindByValue(startTime.ToShortDateString()) == null)
{
// add the item at the start of the list if it's before today, otherwise at the end
// this way we keep a 'sorted' list
if (startTime < DateTime.Today)
dateJump.Items.Insert(0, new ListItem(startTime.ToLongDateString(), startTime.ToShortDateString()));
else
dateJump.Items.Add(new ListItem(startTime.ToLongDateString(), startTime.ToShortDateString()));
}*/
int listoffset = (startTime.Date - DateTime.Today).Days;
if (listoffset < 0) listoffset = 0;
if (listoffset > 6) listoffset = 6;
DateTime jumpDate = startTime.AddDays(-listoffset);
dateJump.Items.Clear();
for (int nCount=-1; nCount<=14; nCount++)
{
DateTime theDay = jumpDate.AddDays(nCount);
ListItem myLI = new ListItem(theDay.ToLongDateString(), theDay.ToShortDateString());
dateJump.Items.Add(myLI);
}
dateJump.SelectedValue = startTime.ToShortDateString();
// retrieve listings for time period
IList listingsForPeriod;
//listingsForPeriod = scheduleHelper.GetListingsForTimePeriod(startTime, endTime);
/* SELECT
* c.oid as c_oid,
* p.oid as p_oid,
* c.name as c_name,
* p.name as p_name,
* *
* FROM
* CHANNEL c,
* PROGRAMME p
* where
* p.channel_oid = c.oid and
* exists (select 1 from SOURCE_CHANNEL_MAPPING scm where scm.channel_oid = c.oid and enabled='Y') and
* start_time < @endTime and
* end_time >= @startTime
* order by
* channel_number,
* p.start_time
* */
// ChannelFactory::getShowsInTimePeriod filter is:
// start_time < @endtime and end_time >= @starttime
// and it should be:
// start_time < @endtime and end_time > @starttime
// so that you actually get programs that start _before_ to the endtime, and end _after_ the starttime
// we're half fixing this by applying a 1 second correction here, to 'fix' the problem
listingsForPeriod = scheduleHelper.GetListingsForTimePeriod(startTime.AddSeconds(1), endTime);
((ArrayList)listingsForPeriod).Sort(new ChannelNumberComparer());
CaseInsensitiveComparer caseInsensitiveComparer = new CaseInsensitiveComparer();
string genreFilter = genreList.SelectedValue;
if ((genreFilter != null) && (genreFilter.Length == 0)) genreFilter = null;
int rowcount = 0;
// add a table row for each channel
foreach (Channel channel in listingsForPeriod)
{
TableRow channelRow = new TableRow();
channelRow.CssClass = "guide_listing_row";
// add channel name & number
TableCell colChannel = new TableCell();
colChannel.CssClass = "guide_chnl_cell";
string channelName = channel.getName();
if (channelName.StartsWith(channel.getChannelNumber().ToString())) // cosmetic stuff for my american friends
{
if (channelName != channel.getChannelNumber().ToString())
{
channelName = channelName.Substring(channel.getChannelNumber().ToString().Length + 1);
}
else
{
channelName = "";
}
}
colChannel.Width = Unit.Percentage(1); // this will break if the tabel ever uses fixed layout
colChannel.HorizontalAlign = HorizontalAlign.Center;
string chnl = channel.getChannelNumber().ToString();
string channelIcon = GetChannelIcon(channel.getChannelNumber(), new string[] {channel.getName(), channelName});
if (channelIcon != null)
{
colChannel.Attributes.Add("class", "channelicon");
HyperLink channelURL = new HyperLink();
colChannel.Controls.Add(channelURL);
channelURL.NavigateUrl = "SearchResults.aspx?listChannels=" + chnl + "&srtOrder=title";
Session["SearchResultsOption"] = "0";
Image channelImage = new Image();
channelURL.Controls.Add(channelImage);
channelImage.ToolTip = chnl + " - " + channelName;
if (channelIconHeight.Length > 0) channelImage.Height = Unit.Pixel(Convert.ToInt16(channelIconHeight));
if (channelIconWidth.Length > 0) channelImage.Width = Unit.Pixel(Convert.ToInt16(channelIconWidth));
channelImage.ImageUrl = Download.GetDownloadUrl(false, true, Download.InternalFiles.ChannelIcon, Server.UrlEncode(channelIcon));
if (useChannelIcons == "chnlBoth")
{
TableCell channelText = new TableCell();
colChannel.Controls.Add(channelText);
channelText.Text =
"<span class=\"channelnumber\"><a href=\"SearchResults.aspx?listChannels=" + chnl + "&srtOrder=title" + "\"><b>" + chnl + "</b></a></span><br />" +
"<span class=\"channelname\"><a href=\"SearchResults.aspx?listChannels=" + chnl + "&srtOrder=title" + "\"><nobr>" + channelName + "</nobr></a></span>";
}
}
else
{
Session["SearchResultsOption"] = "0";
if (useChannelIcons == "chnlBoth")
{
TableCell channelText = new TableCell();
colChannel.Controls.Add(channelText);
channelText.Text =
"<span class=\"channelnumber\"><a href=\"SearchResults.aspx?listChannels=" + chnl + "&srtOrder=title" + "\"><b>" + chnl + "</b></a></span><br />" +
"<span class=\"channelname\"><a href=\"SearchResults.aspx?listChannels=" + chnl + "&srtOrder=title" + "\"><nobr>" + channelName + "</nobr></a></span>";
}
else
{
colChannel.Text =
"<span class=\"channelnumber\"><a href=\"SearchResults.aspx?listChannels=" + chnl + "&srtOrder=title" + "\"><b>" + chnl + "</b></a></span><br />" +
"<span class=\"channelname\"><a href=\"SearchResults.aspx?listChannels=" + chnl + "&srtOrder=title" + "\"><nobr>" + channelName + "</nobr></a></span>";
}
}
channelRow.Cells.Add(colChannel);
DateTime prevEndTime = startTime;
int showcount = 0;
// show programmes
foreach (Programme programme in channel.getProgrammeList())
{
int startMinutes = 0;
int endMinutes = 0;
DateTime programStartTime = programme.getStartTime();
// check to see if there are 'gaps' in the schedule that we need to pad
if (prevEndTime < programStartTime)
{
TimeSpan stimespan = prevEndTime.Subtract(startTime);
startMinutes = (int)Math.Round(stimespan.TotalMinutes);
TimeSpan etimespan = programme.getStartTime().Subtract(startTime);
endMinutes = (int)Math.Round(etimespan.TotalMinutes);
TableCell paddingCell = new TableCell();
paddingCell.ColumnSpan = (endMinutes - startMinutes) / minuteSlice;
paddingCell.CssClass = "tborder";
channelRow.Cells.Add(paddingCell);
}
else if (prevEndTime > programStartTime)
{
// this allows for programs that overlap, we just let the previous program spill into the next
// and the later program looks like it starts later
programStartTime = prevEndTime;
}
// calculate start minutes
if (programStartTime <= startTime)
{
startMinutes = 0;
}
else
{
TimeSpan timespan = programStartTime.Subtract(startTime);
startMinutes = (int)Math.Round(timespan.TotalMinutes);
}
// calculate end minutes
if (programme.getEndTime() >= endTime)
{
endMinutes = minuteSpan;
}
else
{
TimeSpan timespan = programme.getEndTime().Subtract(startTime);
endMinutes = (int)Math.Round(timespan.TotalMinutes);
}
// check for programs that we can't display,
// they may either be too narrow, or
// they overlap with other programs
if ((endMinutes - startMinutes) / minuteSlice < 1) continue;
prevEndTime = programme.getEndTime();
// add programme
TableCell programmeCell = new TableCell();
programmeCell.ColumnSpan = (endMinutes - startMinutes) / minuteSlice;
programmeCell.VerticalAlign = VerticalAlign.Top;
bool showProgramme = true;
if (genreFilter != "Choose Genre...")
{
if (programme.getGenreList().Count > 0)
{
ArrayList showGenres = new ArrayList(programme.getGenreList());
showGenres.Sort();
int idx = showGenres.BinarySearch(genreList.SelectedValue, caseInsensitiveComparer);
showProgramme = idx > -1;
}
else
{
showProgramme = false;
}
}
if (showProgramme)
{
ScheduledRecording scheduledRecording = null;
if (knownRecordings.Contains(programme.getOID())) scheduledRecording = (ScheduledRecording)knownRecordings[programme.getOID()];
displayProgramme.FillProgrammeDisplay(Server, programmeCell, programme, scheduledRecording, true);
showcount++;
}
// add programme
channelRow.Cells.Add(programmeCell);
}
// add row to table
if (showcount > 0)
{
if (rowcount % TimelineRepeat == 0)
{
// put table header
guideView.Rows.Add(createHeaderRow());
}
rowcount++;
guideView.Rows.Add(channelRow);
}
}
guideView.Rows.Add(createHeaderRow());
displayProgramme.Dispose();
}
private static string channelIconPath;
private static string[] channelIconExtensions;
private string GetChannelIcon(int channelNumber, string[] channelNames)
{
if (useChannelIcons == "chnlIcon" || useChannelIcons == "chnlBoth")
{
// Get the Channel Icon Directory
if (channelIconPath == null)
{
lock (typeof(guide))
{
if (channelIconPath == null)
{
channelIconPath = Path.Combine(Global.Settings.GetInstallDir(), @"media\ChannelLogos");
channelIconExtensions = Global.Settings.channelIconExtensions.Split(',');
}
}
}
Hashtable channelIconCache = (Hashtable)Cache["channelIconCache"];
if (channelIconCache == null)
{
lock (typeof(guide))
{
channelIconCache = (Hashtable)Cache["channelIconCache"];
if (channelIconCache == null)
{
channelIconCache = new Hashtable();
Cache.Add(
"channelIconCache",
channelIconCache,
new CacheDependency(channelIconPath),
DateTime.MaxValue,
TimeSpan.Zero,
CacheItemPriority.Normal,
null);
}
}
}
if (channelIconCache.ContainsKey(channelNumber))
{
return (string)channelIconCache[channelNumber];
}
lock (channelIconCache)
{
if (channelIconCache.ContainsKey(channelNumber))
{
return (string)channelIconCache[channelNumber];
}
string channelIconFile = null;
foreach (string channelName in channelNames)
{
foreach (string channelIconExtension in channelIconExtensions)
{
string cleanName = channelName;
string channelNameWork = channelName;
while (cleanName.Contains("/"))
{
if (channelNameWork.Contains("/"))
{
cleanName = channelNameWork.Remove(channelNameWork.IndexOf("/"), 1);
channelNameWork = cleanName;
}
}
string probeFile = cleanName + "." + channelIconExtension;
if (File.Exists(Path.Combine(channelIconPath, probeFile)))
{
channelIconFile = probeFile;
break;
}
}
if (channelIconFile != null) break;
}
channelIconCache[channelNumber] = channelIconFile;
return channelIconFile;
}
}
return null;
}
private TableRow createHeaderRow()
{
return new TableHeaderRow(guideParams, startTime);
}
private class ChannelNumberComparer : IComparer
{
#region IComparer Members
public int Compare(object x, object y)
{
return ((Channel)x).channelNumber.CompareTo(((Channel)y).channelNumber);
}
#endregion
}
private class TableHeaderRow : TableRow, INamingContainer
{
public TableHeaderRow(Settings guideParams, DateTime startTime)
{
TableRow headerRow = this;
TableCell colChannel = new TableCell();
colChannel.CssClass = "header";
colChannel.Wrap = false;
headerRow.Cells.Add(colChannel);
if (useChannelIcons == "chnlBoth")
{
colChannel = new TableCell();
headerRow.Cells.Add(colChannel);
colChannel.CssClass = "header";
}
for (int mins = 0; mins < minuteSpan; mins += minuteInterval)
{
TableCell colTimeslot = new TableCell();
colTimeslot.ColumnSpan = minuteInterval / minuteSlice;
colTimeslot.CssClass = "header";
colTimeslot.Text = startTime.AddMinutes(mins).ToShortTimeString();
colTimeslot.Wrap = false;
headerRow.Cells.Add(colTimeslot);
}
addViewButton(headerRow.Cells[0], "left", "<<");
addViewButton(headerRow.Cells[headerRow.Cells.Count - 1], "right", ">>");
}
private void addViewButton(TableCell colChannel, string mode, string text)
{
LinkButton viewButton = new LinkButton();
viewButton.Text = "<span>" + HttpContext.Current.Server.HtmlEncode(text) + "</span>";
viewButton.CssClass = "btn-normal-tiny";
viewButton.Style.Add("float", mode);
viewButton.ID = "view" + mode + "button";
colChannel.Controls.Add(viewButton);
colChannel.Controls.Add(new LiteralControl("<div style='padding-top: 4px'>" + colChannel.Text + "<div/>"));
}
}
private void GetCookieValues()
{
HttpCookie cookie = Request.Cookies["minuteSpan"];
minuteSpan = cookie != null ? Convert.ToInt32(cookie.Value) : 120;
cookie = Request.Cookies["minuteInterval"];
minuteInterval = cookie != null ? Convert.ToInt32(cookie.Value) : 30;
cookie = Request.Cookies["minuteSlice"];
minuteSlice = cookie != null ? Convert.ToInt32(cookie.Value) : 1;
cookie = Request.Cookies["TimelineRepeat"];
TimelineRepeat = cookie != null ? Convert.ToInt32(cookie.Value) : 10;
cookie = Request.Cookies["useChannelIcons"];
useChannelIcons = cookie != null ? cookie.Value : "chnlText";
cookie = Request.Cookies["channelIconHeight"];
channelIconHeight = cookie != null ? cookie.Value : "";
cookie = Request.Cookies["channelIconWidth"];
channelIconWidth = cookie != null ? cookie.Value : "";
}
}
}